<?php
/**
 * Created by PhpStorm.
 * User: zhj
 * Date: 2019/3/7
 * Time: 17:29
 */


namespace app\index\controller;

use think\Controller;

/**
 * 前端首页控制器
 */
class Msg extends IndexBase
{
    public $msg ;
    public function __construct()
    {
        $this->msg = new \app\common\model\Msg();
        parent::__construct();
    }
    public function addMsg()
    {
        $data = input('post.');
        $user_id = 1;//session('user_id');
        if(!$user_id){
            $this->error('请先登录~',url('login/index'),2);
        }
        $city_id = session('city_id');
        IS_POST && $res = $this->msg->addMsg($data,$user_id,$city_id);
        if($res['code']){
            $this->success($res['msg'],url('msgList'));
        }else{
            $this->error($res['msg'],'./');
        }
    }

    public function msgList()
    {
        $user_id = session('userid');
        if(!$user_id){
            $this->error('请先登录~',url('login/index'),2);
        }
        $where['user_id'] = $user_id;
        $msg_list = $this->msg->getMsgList($where);
        $this->assign('list',$msg_list);
        return $this->fetch('/index/msg');
    }
}